package main

import (
	"fmt"
)

func bSearch(nums []int, value int) (indexs []int) {
	low := 0
	high := len(nums) - 1
	var mid int
	for {
		mid = (low + high) / 2
		if nums[mid] == value {
			break
		} else if nums[mid] < value {
			low = mid + 1
		} else {
			high = mid - 1
		}
		if low > high {
			break
		}
	}

	indexs = append(indexs, mid)
	if mid == len(nums) - 1 {
		for i := mid - 1; i >= 0; i-- {
			if nums[i] == value {
				indexs = append(indexs, i)
			} else {
				break
			}
		}
	}
	if mid == 0 {
		for i := mid + 1; i < len(nums); i++ {
			if nums[i] == value {
				indexs = append(indexs, i)
			} else {
				break
			}
		}
	}
	for i := mid - 1; i >= 0; i-- {
		if nums[i] == value {
			indexs = append(indexs, i)
		} else {
			break
		}
	}
	for i := mid + 1; i < len(nums); i++ {
		if nums[i] == value {
			indexs = append(indexs, i)
		} else {
			break
		}
	}
	return indexs
}

func main() {
	nums := []int{1,2,2,3,4,7,9,9}
	value := 1
	fmt.Println(bSearch(nums, value))
}
